using System;
using System.Collections.Generic;
using System.Linq;

namespace Catastrophe.Common.ObjM
{
	public class Ggo<T> where T : class, new()
	{
		private static T _t;

		private static readonly object ObjLock = new object();

		public static T GetObj
		{
			get
			{
				lock (Ggo<T>.ObjLock)
				{
					if (Ggo<T>._t == null)
					{
						Ggo<T>._t = new T();
					}
				}
				return Ggo<T>._t;
			}
			set
			{
				Ggo<T>._t = value;
			}
		}

		private Ggo()
		{
		}
	}
	public class Ggo
	{
		public static Dictionary<string, object> DicAry = new Dictionary<string, object>();

		public static T GetObj<T>() where T : class, new()
		{
			Type t2 = typeof(T);
			if (Ggo.DicAry.Keys.Any((string x) => x.Equals(t2.Name)))
			{
				return (T)Ggo.DicAry[t2.Name];
			}
			return Ggo<T>.GetObj;
		}

		public static void AddDicAry(Dictionary<string, dynamic> dic)
		{
			foreach (string key in dic.Keys)
			{
				Ggo.DicAry.Add(key, dic[key]);
			}
		}
	}
}
